﻿using Prices;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TestPrices
{
    [TestClass()]
    public class ProductTest
    {
        [TestMethod()]
        public void ProductConstructorTest()
        {
            string name = "Kolio"; // TODO: Initialize to an appropriate value
            Decimal price = (decimal)4565.445; // TODO: Initialize to an appropriate value
            Product target = new Product(name, price);
            Assert.AreEqual<decimal>(price, target.Price);
            Assert.AreEqual<string>(name, target.Name);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException), "Name cannot be null")]
        public void NullNameInConstructorTest()
        {
            string name = null;
            decimal price = (decimal)5.9;
            Product target = new Product(name, price);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException), "Price cannot be negative")]
        public void NegativePriceInConstructorTest()
        {
            string name = "Kolio";
            decimal price = (decimal)-555.5465;
            Product target = new Product(name, price);
        }
 
        [TestMethod()]
        [DeploymentItem("Product.dll")]
        public void OnPriceIncresedTest()
        {
            bool isOK = false;
            Product target = new Product("Nokia", (decimal)256.99); // TODO: Initialize to an appropriate value
            target.PriceIncresed += delegate(object sender, PriceIncresedEventArgs eventArgs)
                {
                    isOK = true;
                };

            Decimal oldPrice = target.Price; // TODO: Initialize to an appropriate value
            Decimal newPrice = (decimal)300.98; // TODO: Initialize to an appropriate value
            target.Price = newPrice;

            Assert.AreEqual(true, isOK);
        }

        [TestMethod()]
        public void NameTest()
        {
            string name = "Nenko"; // TODO: Initialize to an appropriate value
            Decimal price = (decimal)545; // TODO: Initialize to an appropriate value
            Product target = new Product(name, price); // TODO: Initialize to an appropriate value
            string actual = target.Name;
            Assert.AreEqual<string>(name, actual);
        }

        [TestMethod()]
        public void PriceTest()
        {
            string name = "Ciklopko"; // TODO: Initialize to an appropriate value
            Decimal price = (decimal)5655.954; // TODO: Initialize to an appropriate value
            Product target = new Product(name, price); // TODO: Initialize to an appropriate value
            Decimal actual;
            Decimal expected = (decimal)5465465.545465;
            target.Price = expected;
            actual = target.Price;

            Assert.AreEqual<decimal>(expected, actual);
        }
    }
}
